
if( SERVER ) then
   
 	AddCSLuaFile( "shared.lua" ) 
 	SWEP.HoldType = "pistol";
 
 end 

SWEP.Base = "ts2_base";
   
SWEP.Spawnable			= false 
SWEP.AdminSpawnable		= false 
   
SWEP.ViewModel			= "models/weapons/v_shot_xmbeef.mdl"
SWEP.WorldModel			= "models/weapons/w_boom_xmbeef.mdl"
SWEP.Primary.Sound			= Sound( "Weapon_M3.Single" )

SWEP.PrintName = "Door Breacher";
SWEP.TS2Desc = "Blow a door down.";


SWEP.ShotgunReload = true;

SWEP.Primary.Recoil			= .1
SWEP.Primary.RecoilAdd			= 0
SWEP.Primary.RecoilMin = .1
SWEP.Primary.RecoilMax = 3
 
SWEP.Primary.ViewPunchMul = 70;
SWEP.Primary.Damage			= 0
SWEP.Primary.NumShots		= 1 
 
SWEP.TS2HoldType = "RIFLE";

SWEP.Primary.DoorBreach = true;
SWEP.Primary.HighPowered = true;
SWEP.Primary.ClipSize = 6;
SWEP.Primary.DefaultClip = 6;
SWEP.Primary.Ammo = "smg1";
SWEP.Primary.Delay = 1;
SWEP.Primary.Automatic = false;
SWEP.Primary.SpreadCone = Vector( .04, .04, 0 );

SWEP.Primary.IronSightPos = Vector( -9.0, 4.0, -5.0 );
SWEP.Primary.IronSightAng = Vector( -.5, -1.0, 0.0 );

SWEP.Primary.HolsteredPos = Vector( 10.8, -5.0, -2.0 );
SWEP.Primary.HolsteredAng = Vector( -5.0, 50.0, 0.0 );

SWEP.ItemWidth = 3;
SWEP.ItemHeight = 1;


SWEP.IconCamPos = Vector( 8, 58, 50 ) 
SWEP.IconLookAt = Vector( 1, 0, 0 ) 
SWEP.IconFOV = 12

SWEP.Price = 850
   
   
function SWEP:PrimaryAttack()
   

	local bullet = {} 
	bullet.Num 		= 1;
	bullet.Src 		= self.Owner:GetShootPos()			
	bullet.Dir 		= self.Owner:GetAimVector()			
	bullet.Spread 	= Vector( .1, .1, 0 )
	bullet.Tracer	= 0								
	bullet.Force	= 75									
	bullet.Damage	= 0;
	 	 
	self.Owner:FireBullets( bullet ) 
		

	local trace = { }
	trace.start = self.Owner:EyePos();
	trace.endpos = trace.start + self.Owner:GetAimVector() * 4096;
	trace.filter = self.Owner;
	
	local tr = util.TraceLine( trace );
		
	if( tr.Hit ) then
		self.Weapon:EmitSound( Sound( "Weapon_Shotgun.Single" ) );
	else
		self.Weapon:EmitSound( Sound( "Weapon_Shotgun.Single" ) );
	end
		
	if( SERVER ) then
		
		local power = 0.5;
		local norm = ( self.Owner:EyePos() - tr.HitPos ):Normalize();
		
		if( SERVER and tr.Entity:IsValid() and ( tr.Entity:GetClass() == "prop_door_rotating" or tr.Entity:GetClass() == "func_door_rotating" ) ) then
		
			tr.Entity:Fire( "unlock", "", 0 );
			self.Owner:ConCommand( "+use\n" );
			timer.Simple( .1, self.Owner.ConCommand, self.Owner, "-use\n" );
		
		end
		
		if( tr.Entity:IsValid() and tr.Entity:GetClass() == "prop_door_rotating" ) then
		
			if( true ) then
			
				tr.Entity:EmitSound( Sound(  "physics/wood/wood_box_impact_hard3.wav" ) );
			
				if( SERVER ) then

					local pos = tr.Entity:GetPos();
					local ang = tr.Entity:GetAngles();
					local model = tr.Entity:GetModel();
					local skin = tr.Entity:GetSkin();
					
					tr.Entity:SetNotSolid( true );
					tr.Entity:SetNoDraw( true );
					
					local function ResetDoor( door, fakedoor )
						door:SetNotSolid( false );
						door:SetNoDraw( false );
						fakedoor:Remove();
					end
					
					local norm = ( pos - self.Owner:GetPos() ):Normalize();
					local push = 10000 * norm;


					local ent = ents.Create( "prop_physics" );
					ent:SetPos( pos );
					ent:SetAngles( ang );
					ent:SetModel( model );
					if( skin ) then
						ent:SetSkin( skin );
					end
					ent:Spawn();
					
					timer.Simple( .2, ent.SetVelocity, ent, push );					
					timer.Simple( .2, ent:GetPhysicsObject().ApplyForceCenter, ent:GetPhysicsObject(), push );
																
					timer.Simple( 300, ResetDoor, tr.Entity, ent );
					
				end

			end
		
		end
		
	end

end

